
let listData = [
	{
		images: "/pages/images/1.jpg",
	},
	{
		images: "/pages/images/19.jpg",
	},
	{
		images: "/pages/images/18.jpg",
	},
	{
		images: "/pages/images/20.jpg",
	}
];

Page({
	data: {
		// isIphoneX: false,
		listData: [],
		// beforeExtraNodes: [
		// 	{
		// 		dragId: "before0",
		// 		destKey: 0,
		// 		slot: "before",
		// 		fixed: true
		// 	}
		// ],
		// afterExtraNodes: [
		// 	{
		// 		dragId: "after0",
		// 		destKey: 0,
		// 		slot: "after",
		// 		fixed: true
		// 	},
		// 	{
		// 		dragId: "after9",
		// 		destKey: 9,
		// 		slot: "plus",
		// 		fixed: true
		// 	}
		// ],
		// pageMetaScrollTop: 0,
		// scrollTop: 0
	},
	sortEnd(e) {
		console.log("sortEnd", e.detail.listData)
		this.setData({
			listData: e.detail.listData
		});
	},
	change(e) {
		console.log("change", e.detail.listData)
	},
	sizeChange(e) {
		wx.pageScrollTo({scrollTop: 0})
		this.setData({
			size: e.detail.value
		});
		this.drag.init();
	},
	itemClick(e) {
		console.log(e);
	},
	toggleFixed(e) {
		let key = e.currentTarget.dataset.key;

		let {listData} = this.data;

		listData[key].fixed = !listData[key].fixed

		this.setData({
			listData: listData
		});

		this.drag.init();
	},
	add(e) {
		let listData = this.data.listData;
		listData.push({
			dragId: `item${listData.length}`,
			title: "这个绝望的世界没有存在的价值，所剩的只有痛楚",
			description: "思念、愿望什么的都是一场空，被这种虚幻的东西绊住脚，什么都做不到",
			images: "/assets/image/swipe/1.png",
			fixed: false
		});
		setTimeout(() => {
			this.setData({
				listData,
				afterExtraNodes: [
					{
						destKey: 0,
						slot: "after",
						fixed: true
					},
					{
						destKey: listData.length - 1,
						slot: "plus",
						fixed: true
					}
				]
			});
			this.drag.init();
		}, 300)

	},
	scroll(e) {
		this.setData({
			pageMetaScrollTop: e.detail.scrollTop
		})
	},
	// 页面滚动
	onPageScroll(e) {
		this.setData({
			scrollTop: e.scrollTop
		});
	},
	onLoad() {
		this.drag = this.selectComponent('#drag');
		// 模仿异步加载数据
		setTimeout(() => {
			this.setData({
				listData: listData
			});
			this.drag.init();
		}, 100)
	}
})